﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YAPL.Language.Core.Exceptions;

namespace YAPL.Language.Core.Types {
	public class YAPLBoolean : YAPLObject {
		private bool _boolValue;
		public YAPLBoolean(bool boolValue)
			: base("YAPLBoolean") {
			_boolValue = boolValue;
		}

		public bool BoolValue {
			get { return _boolValue; }
			set { _boolValue = value; }
		}

		public override string ToString() {
			return BoolValue.ToString().ToLower();
		}

		public override object Value {
			get {
				return _boolValue;
			}
		}
		#region operator overrides
		public override YAPLObject And(YAPLObject other) {
			if (other is YAPLBoolean) {
				var otherValue = (other as YAPLBoolean).BoolValue;
				return new YAPLBoolean(BoolValue && otherValue);
			}
			return base.And(other);
		}

		public override YAPLObject Or(YAPLObject other) {
			if (other is YAPLBoolean) {
				var otherValue = (other as YAPLBoolean).BoolValue;
				return new YAPLBoolean(BoolValue || otherValue);
			}
			return base.Or(other);
		}

		public override YAPLObject Not() {
			return new YAPLBoolean(!BoolValue);
		}
		#endregion
	}
}
